﻿Public Class FormVersions
    Public oVersion As ClassArchive
    Public sActuel As String

    Private Enum EtatCar
        Pareil = 0
        Nouveau = 1
        Supprime = 2
    End Enum

    Public Sub New()
        InitializeComponent()
        Me.oVersion = Nothing
        Me.sActuel = ""
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If Me.ListView1.SelectedItems.Count > 0 Then
            Me.RichTextBox1.Visible = False
            Dim oItem As ListViewItem = Me.ListView1.SelectedItems(0)
            Me.oVersion = oItem.Tag
            Me.RichTextBox1.Text = Me.oVersion.zContenu.GetValeur
            For Each oItem2 As ListViewItem In Form1.ListViewMarqueurs.CheckedItems
                Dim oMasque As ClassMarqueur = oItem2.Tag
                oMasque.Marquer(Me.RichTextBox1)
            Next
            Me.RichTextBox1.Visible = True
        End If
    End Sub

    Private Sub FormVersions_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Me.ListView1.Columns(0).Width = Me.ListView1.Width
        If Me.ListView1.Items.Count > 0 Then Me.ListView1.Items(0).Selected = True
        Me.TextBoxCommande.Text = My.Settings.CommandeComp
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Me.ListView1.SelectedItems.Count > 0 Then
            'Récupérer la version courante
            Dim oItem As ListViewItem = Me.ListView1.SelectedItems(0)
            Me.oVersion = oItem.Tag
            'Créer un fichier temporaire
            Dim sTempFile As String = My.Computer.FileSystem.GetTempFileName()
            My.Computer.FileSystem.WriteAllText(sTempFile, Me.oVersion.zContenu.GetValeur, False, System.Text.Encoding.Default)
            'Lancer la ligne de commande
            Dim sCommande As String = Me.TextBoxCommande.Text
            sCommande = sCommande.Replace("%f", "%F")
            sCommande = sCommande.Replace("%v", "%V")
            sCommande = sCommande.Replace("%F", Form1.DocumentCourant.Chemin)
            sCommande = sCommande.Replace("%V", sTempFile)
            FormErreur.Reset()
            FormErreur.AjouteErreur(Commun.RunShell(sCommande))
            FormErreur.ShowSiErreur()
            If My.Computer.FileSystem.FileExists(sTempFile) Then My.Computer.FileSystem.DeleteFile(sTempFile)
            My.Settings.CommandeComp = Me.TextBoxCommande.Text
        Else
            MsgBox("Vous devez d'abord sélectionnez la version à comparer", MsgBoxStyle.Exclamation)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        My.Settings.CommandeComp = Me.TextBoxCommande.Text
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.CommandeComp = Me.TextBoxCommande.Text
    End Sub
End Class